import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { User } from '@/types/user'

export default defineStore(
  'cp-user',
  () => {
    const user = ref<User>()

    // 设置用户
    const setUser = (u: User) => {
      user.value = u
    }
    // 删除用户
    const delUser = () => {
      user.value = undefined
    }

    const URL = ref('')
    const setUrl = (s: string) => {
      URL.value = s
    }
    return {
      user,
      setUser,
      delUser,
      URL,
      setUrl
    }
  },
  {
    persist: true // 默认开启localStorage本地存储 key :'cp-user'
    // persist: {
    //   key: 'userInfo', // 存储的key
    //   storage: sessionStorage, // 存储的模式
    //   paths: ['user.token'] // 指定存储的数据
    // }
  }
)
